<template>
	<view class="container">
		<view class="card" v-for="(item,index) in msgList" :key="index">
			<view class="card_header">
				<text>{{ item.module == 'zytl' ? '中医调理' : '产品介绍' }}</text>
				<text class="red" v-if="item.status == 0">待处理</text>
				<text class="blue" v-if="item.status == 1">处理中</text>
				<text class="success_color" v-if="item.status == 2">已处理</text>
			</view>
			<view class="card_body" @click="goDetail(item.id)">
				<image :src="item.module_info.imageUrl" mode=""></image>
				<view class="detail">
					<text class="title">{{ item.module_info.title }}</text>
					<text>姓名: {{ item.name }}, 电话: {{ item.phone }}</text>
					<text>备注: {{ item.content || '未填写' }}</text>
				</view>
			</view>
			<view class="card_foot">
				<text>预约时间: {{ item.createtime_text }}</text>
				<u-icon @click="del(item.id, index)" name="trash" color="#f00" size="36"></u-icon>
			</view>
		</view>
		<u-loadmore v-if="msgList.length > 0" :status="status" margin-bottom="50" />
		<u-empty v-if="msgList.length == 0" text="暂无数据" mode="order" margin-top="300"></u-empty>
	</view>
</template>

<script>
	import { adminMsgList, delMsg } from '../../api/api'
	export default {
		data() {
			return {
				msgList: [],
				pageIndex: 1,
				status: 'loading'
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				if(this.status == 'nomore') return;
				adminMsgList({
					token: uni.getStorageSync('userInfo').token,
					type: 'yuyue',
					page: this.pageIndex,
					limit: 10
				}).then(res => {
					if (res.code == 1) {
						if (res.data.length == 0) {
							this.status = 'nomore'
							return;
						}
						if (res.data.length < 10) {
							this.status = 'nomore'
						}
						this.msgList.push(...res.data)
					} else {
						this.$u.toast(res.msg)
					}
					uni.stopPullDownRefresh();
				})
			},
			goDetail(id) {
				uni.navigateTo({
					url: 'msg_detail?id=' + id
				})
			},
			del(id, index) {
				uni.showModal({
				    title: '温馨提示',
				    content: '是否确认删除该信息?',
				    success: (res) => {
				        if (res.confirm) {
				            delMsg({
				            	token: uni.getStorageSync('userInfo').token,
				            	id
				            }).then(res => {
				            	if(res.code == 1) {
				            		this.msgList.splice(index, 1)
									this.$u.toast(res.msg)
				            	} else {
				            		this.$u.toast(res.msg)
				            	}
				            })
				        } else if (res.cancel) {
				            this.$u.toast('取消删除')
				        }
				    }
				});
				
			}
		},
		onReachBottom() {
			this.pageIndex++;
			this.getList()
		},
		onPullDownRefresh() {
			this.pageIndex = 1;
			this.msgList = []
			this.status = 'loading'
			this.getList()
		}
	}
</script>

<style lang="scss">
.container {
	width: 100%;
	.card {
		width: 100%;
		background-color: #fff;
		margin-bottom: 25rpx;
		.card_header {
			display: flex;
			justify-content: space-between;
			padding: 30rpx;
			border-bottom: 1px solid #eee;
			.success_color {
				color: #56bb37;
			}
			.red {
				color: #f00;
			}
			.blue {
				color: #007AFF;
			}
		}
		.card_body {
			display: flex;
			padding: 30rpx;
			border-bottom: 1px solid #eee;
			image {
				width: 150rpx;
				height: 150rpx;
				margin-right: 20rpx;
			}
			.detail {
				display: flex;
				flex-direction: column;
				justify-content: center;
				color: #999;
				text {
					display: block;
					width: 500rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					
				}
				text:first-child{
					margin-bottom: 20rpx;
					color: #333;
					font-size: 30rpx;
				}
			}
		}
		.card_foot {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			padding: 30rpx;
			color: #999;
			font-size: 24rpx;
		}
	}
}
</style>
